﻿// WhiteTestDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "WhiteTestDlg.h"
#include "afxdialogex.h"


// CWhiteTestDlg 对话框

IMPLEMENT_DYNAMIC(CWhiteTestDlg, CDialogEx)

CWhiteTestDlg::CWhiteTestDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_WHITE, pParent)
	, m_bFlag1(FALSE)
	, m_bScanX(FALSE)
	, m_bScanY(FALSE)
	, m_nScanDis(0)
	, m_nThreshold(0)
	, m_nFilter(0)
	, m_bFlag2(FALSE)
	, m_dHigh(0)
	, m_dLow(0)
	, Power(0)
	, PowerAdd(0)
	, PowerSpec(0)
	, m_nStainMax2(0)
	, m_dPowerMax(0)
	, m_dPowerMin(0)
	, Spec99(0)
	, PowerCH1Flag(FALSE)
	, PowerWhiteFlag(FALSE)
{

}

CWhiteTestDlg::~CWhiteTestDlg()
{
}

void CWhiteTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_CHECK1, m_bFlag1);
	DDX_Check(pDX, IDC_CHECK2, m_bScanX);
	DDX_Check(pDX, IDC_CHECK3, m_bScanY);
	DDX_Text(pDX, IDC_EDIT1, m_nScanDis);
	DDX_Text(pDX, IDC_EDIT2, m_nThreshold);
	DDX_Text(pDX, IDC_EDIT5, m_nFilter);
	DDX_Check(pDX, IDC_CHECK4, m_bFlag2);
	DDX_Text(pDX, IDC_EDIT_HIGH, m_dHigh);
	DDX_Text(pDX, IDC_EDIT_LOW, m_dLow);
	DDX_Text(pDX, IDC_EDIT11, m_nStainMax);
	DDX_Text(pDX, IDC_EDIT12, Power);
	DDX_Text(pDX, IDC_EDIT13, PowerAdd);
	DDX_Text(pDX, IDC_EDIT14, PowerSpec);
	DDX_Text(pDX, IDC_EDIT15, m_nStainMax2);
	DDX_Text(pDX, IDC_EDIT16, m_dPowerMax);
	DDX_Text(pDX, IDC_EDIT17, m_dPowerMin);
	DDX_Text(pDX, IDC_EDIT18, Spec99);
	DDX_Check(pDX, IDC_CHECK6, PowerCH1Flag);
	DDX_Check(pDX, IDC_CHECK7, PowerWhiteFlag);
}


BEGIN_MESSAGE_MAP(CWhiteTestDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, &CWhiteTestDlg::OnBnClickedButtonSave)
	ON_BN_CLICKED(IDC_BUTTON1, &CWhiteTestDlg::OnBnClickedButton1)
END_MESSAGE_MAP()


// CWhiteTestDlg 消息处理程序


BOOL CWhiteTestDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	ReadConfigIni();

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CWhiteTestDlg::OnCancel()
{


	CDialogEx::OnCancel();
}


void CWhiteTestDlg::OnBnClickedButtonSave()
{
	SaveEditValueToConfig();
}

void CWhiteTestDlg::ReadConfigIni()
{
	PowerCH1Flag = gSystemMgr.PowerCH1Flag;
	PowerWhiteFlag = gSystemMgr.PowerWhiteFlag;

	m_bFlag1 = gSystemMgr.m_nStainTestFlag;
	m_bScanX = gSystemMgr.m_nScanXFlag;
	m_bScanY = gSystemMgr.m_nScanYFlag;
	m_nScanDis = gSystemMgr.m_nScanDistance;
	m_nThreshold = gSystemMgr.m_nScanThreshold;
	m_nFilter = gSystemMgr.m_nFilterClose;

	m_bFlag2 = gSystemMgr.m_nBadPointTestFlag;
	m_dHigh = gSystemMgr.m_fHighLimit;
	m_dLow = gSystemMgr.m_fLowLimit;

	m_nStainMax = gSystemMgr.m_nStainMax;

	Power = gSystemMgr.m_dPowerSet;
	PowerAdd = gSystemMgr.m_dPowerAdd;
	PowerSpec = gSystemMgr.m_dPowerSpec;

	m_nStainMax2 = gSystemMgr.m_nStainMax2;
	m_dPowerMax = gSystemMgr.m_dPowerMax;
	m_dPowerMin = gSystemMgr.m_dPowerMin;

	Spec99 = gSystemMgr.Spec99;

	UpdateData(FALSE);
}

void CWhiteTestDlg::SaveEditValueToConfig()
{
	UpdateData(TRUE);

	gSystemMgr.PowerCH1Flag = PowerCH1Flag;
	gSystemMgr.PowerWhiteFlag = PowerWhiteFlag;

	gSystemMgr.m_nStainTestFlag = m_bFlag1;
	gSystemMgr.m_nScanXFlag = m_bScanX;
	gSystemMgr.m_nScanYFlag = m_bScanY;
	gSystemMgr.m_nScanDistance = m_nScanDis;
	gSystemMgr.m_nScanThreshold = m_nThreshold;
	gSystemMgr.m_nFilterClose = m_nFilter;
	gSystemMgr.m_nBadPointTestFlag = m_bFlag2;
	gSystemMgr.m_fHighLimit = m_dHigh;
	gSystemMgr.m_fLowLimit = m_dLow;

	gSystemMgr.m_nStainMax = m_nStainMax;

	gSystemMgr.m_dPowerSet = Power;
	gSystemMgr.m_dPowerAdd = PowerAdd;
	gSystemMgr.m_dPowerSpec = PowerSpec;

	gSystemMgr.m_nStainMax2 = m_nStainMax2;
	gSystemMgr.m_dPowerMax = m_dPowerMax;
	gSystemMgr.m_dPowerMin = m_dPowerMin;

	gSystemMgr.Spec99 = Spec99;

	CString cstr;
	cstr.Format(L"%d", gSystemMgr.PowerCH1Flag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"PowerCH1Flag", cstr);
	cstr.Format(L"%d", gSystemMgr.PowerWhiteFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"PowerWhiteFlag", cstr);

	cstr.Format(L"%d", gSystemMgr.Spec99); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"Spec99", cstr);

	cstr.Format(L"%d", gSystemMgr.m_nStainTestFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nStainTestFlag", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nScanXFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nScanXFlag", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nScanYFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nScanYFlag", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nScanDistance); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nScanDistance", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nScanThreshold); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nScanThreshold", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nFilterClose); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nFilterClose", cstr);

	cstr.Format(L"%d", gSystemMgr.m_nBadPointTestFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nBadPointTestFlag", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_fHighLimit); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_fHighLimit", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_fLowLimit); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_fLowLimit", cstr);

	cstr.Format(L"%d", gSystemMgr.m_nStainMax); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nStainMax", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nStainMax2); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nStainMax2", cstr);

	cstr.Format(L"%.3f", gSystemMgr.m_dPowerSet); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"Power", L"m_dPowerSet", cstr);
	cstr.Format(L"%.3f", gSystemMgr.m_dPowerAdd); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"Power", L"m_dPowerAdd", cstr);
	cstr.Format(L"%.3f", gSystemMgr.m_dPowerSpec); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"Power", L"m_dPowerSpec", cstr);

	cstr.Format(L"%.3f", gSystemMgr.m_dPowerMax); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"Power", L"m_dPowerMax", cstr);
	cstr.Format(L"%.3f", gSystemMgr.m_dPowerMin); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"Power", L"m_dPowerMin", cstr);

}


void CWhiteTestDlg::OnBnClickedButton1()
{
	gSystemMgr.imgRLG.CurrentTest();
}
